package org.example.service.impl;

import org.example.domain.entity.Serial;
import org.example.mapper.SerialMapper;
import org.example.service.IAlipayService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Map;

/*
szy

*/
@Service
public class AlipayServiceImpl implements IAlipayService {

    @Resource
    private SerialMapper serialMapper;

    private SimpleDateFormat form = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    @Override
    public void alipay(Map map) {
        String tradeNo = map.get("trade_no").toString();
        System.out.println("++======+++");
        System.out.println(tradeNo);
        Serial serial = new Serial();
        serial.setSerialId(map.get("trade_no").toString());
        serial.setOutTradeNo(map.get("out_trade_no").toString());
        serial.setReceiptAmount(map.get("receipt_amount").toString());
        serial.setSellerId(map.get("seller_id").toString());
        serial.setBuyerId(map.get("buyer_id").toString());
        serial.setPayType(0);
        try {
            serial.setGmtPayment(form.parse(map.get("gmt_payment").toString()));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        serialMapper.insert(serial);
    }

}
